from commons.entity.po.model import db


class User(db.Model):
    __tablename__ = 'user'

    user_id = db.Column(db.String(20), primary_key=True, info='用户编号')
    password = db.Column(db.String(20, 'utf8mb4_0900_ai_ci'), nullable=False, info='登录密码')
    name = db.Column(db.String(30, 'utf8mb4_0900_ai_ci'), info='用户姓名')
    sex = db.Column(db.String(5), server_default=db.FetchedValue(), info='性别，男，女')
    birthday = db.Column(db.Date, info='出生日期')
    phone = db.Column(db.String(20, 'utf8mb4_0900_ai_ci'), info='联系方式')
    email = db.Column(db.String(30), info='邮箱')
    position = db.Column(db.String(20, 'utf8mb4_0900_ai_ci'), info='职位，员工，经理，财务人员')

    def to_dict(self):
        return {
            "user_id": self.user_id,
            "name": self.name,
            "sex": self.sex,
            "birthday": self.birthday.strftime('%Y-%m-%d') if self.birthday else None,
            "phone": self.phone,
            "email": self.email,
            "position": self.position,
        }

    def to_dict_2(self):
        return {
            "userId": self.user_id,
            "name": self.name,
            "sex": self.sex,
            "birthday": self.birthday.strftime('%Y-%m-%d') if self.birthday else None,
            "phone": self.phone,
            "email": self.email,
            "position": self.position,
        }
